<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
 */
$api = app('Dingo\Api\Routing\Router');

// v2 version API
// add in header    Accept:application/vnd.argo.v1+json
$api->version('v1', [
    'namespace' => 'App\Http\Controllers\Api\V1',
    'middleware' => [
        'cors',
        //'api.throttle'
    ],
    // each route have a limit of 100 of 1 minutes
    //'limit' => 100, 'expires' => 1
], function ($api) {
    // 验证码
    $api->post('requestVerifyCode', [
        'as' => 'users.requestVerifyCode',
        'uses' => 'UserController@requestVerifyCode',
    ]);

    // 校验验证码
    $api->post('checkcode', [
        'as' => 'auth.checkcode',
        'uses' => 'AuthController@checkCode',
    ]);
    // 注册
    $api->post('users', [
        'as' => 'users.store',
        'uses' => 'UserController@store',
    ]);

    // 登录
    $api->post('authorizations', [
        'as' => 'authorizations.store',
        'uses' => 'AuthController@store',
    ]);


    //有赞云初始化接口
    $api->get('youZanInit',[
        'as' => 'youZan.init',
        'uses' => 'YouZanController@publicLogin',
    ]);
    //扫描接口
    $api->get('getinfo',[
        'as' => 'getInfo.store',
        'uses' => 'IdentifyController@getInfoByName',
    ]);

    //推荐内容接口
    $api->get('article',[
        'as' => 'article.store',
        'uses' => 'ArticleController@getArticle',
    ]);

    //找回密码接口
    $api->post('forget/password',[
        'as' => 'forget.password',
        'uses' => 'UserController@resetPassword',
    ]);

    //用户反馈接口
    $api->post('feedback',[
        'as' => 'feedback.store',
        'uses' => 'UserController@userFeedback',
    ]);

    // 刷新token
    $api->put('authorizations/{token_id}', [
        'as' => 'authorizations.update',
        'uses' => 'AuthController@update',
    ]);

    // 获取系统配置
    $api->get('system/option', [
        'as' => 'system.option',
        'uses' => 'AuthController@getSystemOption',
    ]);

    // 获取默认视频封面图
    $api->get('video/cover', [
        'as' => 'video.cover',
        'uses' => 'YouZanController@getVideoCover',
    ]);

    // 需要权限认证
    $api->group(['middleware' => 'api.auth'], function ($api) {
        // 删除token信息
        $api->delete('authorizations/current', [
            'as' => 'authorizations.destroy',
            'uses' => 'AuthController@destroy',
        ]);

        /*---------- User start ----------*/
        // 获取用户信息
        $api->get('user', [
            'as' => 'user.show',
            'uses' => 'UserController@userShow',
        ]);

        // 修改个人信息
        $api->post('information', [
            'as' => 'user.update',
            'uses' => 'UserController@patch',
        ]);

        // 上传头像
        $api->post('uploadAvatar', [
            'as' => 'users.uploadAvatar',
            'uses' => 'UserController@uploadAvatar',
        ]);
        /*---------- User end ----------*/

        //退出登陆接口
        $api->get('logout',[
            'as'   => 'user.logout',
            'uses' => 'AuthController@logout'
        ]);

        //有赞登陆接口
        $api->post('yzylogin',[
            'as' => 'yzy.login',
            'uses' => 'YouZanController@loginYouZanYun',
        ]);

        //有赞登出接口
        $api->post('yzysignout',[
            'as' => 'yzy.signout',
            'uses' => 'YouZanController@yzLoginOut',
        ]);

        //判断有赞用户是否注册及用户今日是否已抢过红包
        $api->post('yzyuser',[
            'as' => 'yzy.user',
            'uses' => 'RedPacketController@hasYouZanInfo',
        ]);

        //更新用户绑定有赞云手机号码
        $api->post('yzymobile',[
            'as' => 'yzy.mobile',
            'uses' => 'UserController@updateYouZanMobile',
        ]);
        //获取是否收藏接口
        $api->get('collection',[
            'as' => 'article.collection',
            'uses' => 'ArticleController@articleCollectStatus',
        ]);
        //获取用户收藏列表
        $api->get('favorite',[
            'as' => 'article.favorite',
            'uses' => 'ArticleController@getUserFavorite',
        ]);
        //收藏推荐内容接口
        $api->post('collect',[
            'as' => 'article.collect',
            'uses' => 'ArticleController@collectArticle',
        ]);
        //取消收藏推荐内容接口
        $api->post('discollect',[
            'as' => 'article.discollect',
            'uses' => 'ArticleController@cancelCollectArticle',
        ]);

        //抢红包
        $api->post('redpackets', [
            'as' => 'redpackets.store',
            'uses' => 'RedPacketController@getRedPackets',
        ]);

        //修改密码
        $api->post('modifypass', [
            'as' => 'modify.pass',
            'uses' => 'UserController@modifyPassword',
        ]);
    });
});
